home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
- //
- // Filename : Timer.cpp
- // Description : Member Definitions Timer class
- // Author : Marnich van Rensburg (2002)
- //
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
-
- #include "timer.h"
-
- Timer :: Timer() // Initialize Our Timer (Get It Ready)
- {
- memset(&TimerData, 0, sizeof(TimerData)); // Clear Our Timer Structure
-
- // Check To See If A Performance Counter Is Available
- // If One Is Available The Timer Frequency Will Be Updated
- if (!QueryPerformanceFrequency((LARGE_INTEGER *) &TimerData.frequency))
- {
- // No Performace Counter Available
- TimerData.performance_timer = FALSE; // Set Performance Timer To FALSE
- TimerData.mm_timer_start = timeGetTime(); // Use timeGetTime() To Get Current Time
- TimerData.resolution = 1.0f/1000.0f; // Set Our Timer Resolution To .001f
- TimerData.frequency = 1000; // Set Our Timer Frequency To 1000
- TimerData.mm_timer_elapsed = TimerData.mm_timer_start; // Set The Elapsed Time To The Current Time
- }
- else
- {
- // Performance Counter Is Available, Use It Instead Of The Multimedia Timer
- // Get The Current Time And Store It In performance_timer_start
- QueryPerformanceCounter((LARGE_INTEGER *) &TimerData.performance_timer_start);
- TimerData.performance_timer = TRUE; // Set Performance Timer To TRUE
- // Calculate The Timer Resolution Using The Timer Frequency
- TimerData.resolution = (float) (((double)1.0f)/((double)TimerData.frequency));
- // Set The Elapsed Time To The Current Time
- TimerData.performance_timer_elapsed = TimerData.performance_timer_start;
- }//if
-
- Start = GetTime();
- } // Timer
-
-
-
-
- float Timer :: GetTime() // Get Time In Milliseconds
- {
- __int64 time; // time Will Hold A 64 Bit Integer
-
- if (TimerData.performance_timer) // Are We Using The Performance Timer?
- {
- QueryPerformanceCounter((LARGE_INTEGER *) &time); // Grab The Current Performance Time
- // Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)
- return ( (float) ( time - TimerData.performance_timer_start) * TimerData.resolution)*1000.0f;
- }
- else
- {
- // Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)
- return( (float) ( timeGetTime() - TimerData.mm_timer_start) * TimerData.resolution)*1000.0f;
- }//if
-
- }// GetTime
-
-
- bool Timer :: CheckFreq(float v_Freq)
- {
- if(v_Freq == 0.0f)
- Start = GetTime();
-
- if ((GetTime() - Start) >= v_Freq)
- {
- Start = GetTime();
- return true;
- }else{
- return false;
- }//if
-
- }// CheckFreq
-